package com.nyist.myticket.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nyist.myticket.biz.entity.CityArea;
import com.nyist.myticket.biz.mapper.CityAreaMapper;
import com.nyist.myticket.biz.service.CityAreaService;
import com.nyist.myticket.core.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yangxiaogen
 * @since 2021-01-05
 */
@Service
public class CityAreaServiceImpl extends BaseService<CityAreaMapper, CityArea> implements CityAreaService {

    @Autowired
    private CityAreaMapper cityAreaMapper;

    @Override
    public CityArea queryByAreaCode(String areaCode) {
        QueryWrapper<CityArea> cityAreaQueryWrapper = new QueryWrapper<>();
        cityAreaQueryWrapper.eq("area_code",areaCode);

        return cityAreaMapper.selectOne(cityAreaQueryWrapper);
    }

    @Override
    public CityArea queryByAreaName(String areaName) {
        QueryWrapper<CityArea> cityAreaQueryWrapper = new QueryWrapper<>();
        cityAreaQueryWrapper.eq("area_name",areaName);

        return cityAreaMapper.selectOne(cityAreaQueryWrapper);
    }

    @Override
    public List<CityArea> queryByAreaLevel(String areaLevel) {
        QueryWrapper<CityArea> cityAreaQueryWrapper = new QueryWrapper<>();
        cityAreaQueryWrapper.eq("area_level",areaLevel);

        return cityAreaMapper.selectList(cityAreaQueryWrapper);
    }

    @Override
    public List<CityArea> queryByAreaLevelAndParentAreaCode(String areaLevel, String parentAreaCode) {
        QueryWrapper<CityArea> cityAreaQueryWrapper = new QueryWrapper<>();
        cityAreaQueryWrapper.eq("area_level",areaLevel);
        cityAreaQueryWrapper.eq("parent_area_code",parentAreaCode);

        return cityAreaMapper.selectList(cityAreaQueryWrapper);
    }

}
